package yunjiao.designpatterns.state;

import lombok.Getter;
import lombok.Setter;

/**
 * TODO
 *
 * @author yangyunjiao
 */
@Getter
@Setter
public class DeliveryAttempted implements ShipmentState {

    protected String reasonForUndelivered;

    public DeliveryAttempted(String reasonForUndelivered) {
        super();
        this.reasonForUndelivered = reasonForUndelivered;
    }

    @Override

    public void processShipment(ShipmentContext context) {
        Shipment shipment = context.getShipment();
        System.out.printf("Order#'%s' for '%s' has status '%s (%s)'.\nDelivery Address is '%s'\n",
                shipment.getOrderNumber(), shipment.getOrderItem(), name(), reasonForUndelivered,
                shipment.getDeliveryAddress());
        System.out.println("--------------------------------------------------------------");

        // setting flag to make the delivery at next attempt.
        // we can set it logically as well instead of hard coding.
        context.setCustomerAtLocation(true);
        context.setCurrentState(new OutForDelivery());
    }

    @Override
    public String name() {
        return "Delivery Attempted";
    }
}
